package com.zcoj.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zcoj.mapper.LanguageMapper;
import com.zcoj.pojo.Dto.Language;
import com.zcoj.service.LanguageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * Service实现
 * @author 剩xia的盛夏
 * @date 2023/02/24 16:16
 */
@Service
public class LanguageServiceImpl implements LanguageService {

    @Autowired
    private LanguageMapper languageMapper;

    @Override
    public Integer create(Language language) {
        languageMapper.insert(language);
        return language.getId();
    }

    @Override
    public void deleteById(Integer id) {
        languageMapper.deleteById(id);
    }



    @Override
    public void updateById(Language language) {
        languageMapper.updateById(language);
    }



    @Override
    public Language findById(Integer id) {
        return languageMapper.selectById(id);
    }

    @Override
    public Language findOne(Language language) {
        Wrapper<Language> wrapper = new QueryWrapper<>(language);
        return languageMapper.selectOne(wrapper);
    }

    @Override
    public List<String> findList() {
        QueryWrapper<Language> wrapper = new QueryWrapper<>();
        wrapper.select("content_type");
        List<Language> languages = languageMapper.selectList(wrapper);
        List<String> languageList=new ArrayList<>();

        for (Language language : languages) {
            languageList.add(language.getContentType());
        }
        return languageList;
    }


    @Override
    public long count(Language language) {
        Wrapper<Language> wrapper = new QueryWrapper<>(language);
        return languageMapper.selectCount(wrapper);
    }
}
